-
Notifications
You must be signed in to change notification settings - Fork 71
Added parameter to sd.concatenate
to control whether to merge coordinate systems with the same name
#919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #919 +/- ##
=======================================
Coverage 92.14% 92.15%
=======================================
Files 48 48
Lines 7473 7479 +6
=======================================
+ Hits 6886 6892 +6
Misses 587 587
🚀 New features to boost your workflow:
|
…uffix-to-coordinate-systems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new merge_coordinate_systems_on_name
flag to sd.concatenate
, allowing users to control whether coordinate systems with the same name are merged or given distinct suffixes.
Key changes:
- Add
merge_coordinate_systems_on_name
parameter toconcatenate
API and forward it to the renaming helper. - Update
_fix_ensure_unique_element_names
to propagate transformations and apply suffixes (or not) based on the new flag. - Add a parametrized test in
test_concatenate_merge_coordinate_systems_on_name
to verify both behaviors.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
tests/core/test_concatenate.py | New test test_concatenate_merge_coordinate_systems_on_name checks merged vs. suffixed CS names. |
src/spatialdata/_core/concatenate.py | - Added merge_coordinate_systems_on_name to signature and doc.\n- Enhanced _fix_ensure_unique_element_names to handle CS transformations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new parameter, merge_coordinate_systems_on_name, to sd.concatenate in order to control whether coordinate system names are merged (i.e. kept unchanged) or suffixed with a key.
- Adds merge_coordinate_systems_on_name to both the public concatenate function and the internal _fix_ensure_unique_element_names helper.
- Updates the test suite to verify that coordinate system names are handled as expected based on the parameter value.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
tests/core/test_concatenate.py | New test verifying the behavior of merge_coordinate_systems_on_name in concatenated outputs. |
src/spatialdata/_core/concatenate.py | Updates to function signatures and implementation to support the merge_coordinate_systems_on_name flag. |
modify_tables_inplace: bool, | ||
merge_coordinate_systems_on_name: bool, | ||
) -> list[SpatialData]: | ||
elements_by_sdata: list[dict[str, SpatialElement]] = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this refactoring is fine
src/spatialdata/_core/concatenate.py
Outdated
# Handle coordinate systems and transformations | ||
for element_name, element in elements.items(): | ||
# Get the original element from the input sdata | ||
original_name = element_name.replace(f"-{suffix}", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for this, we already know el
when constructing the elements
dict.
src/spatialdata/_core/concatenate.py
Outdated
raise TypeError(f"Expected 'transformations' to be a dict, but got {type(transformations).__name__}.") | ||
|
||
# Remove any existing transformations from the new element | ||
remove_transformation(element, remove_all=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code removes all the transformations, then checks (at every iteration) for the value of merge_coordinate_system_on_name
, and when it is true it restores the original transformation.
This is convoluted and note needed, as one could check merge_coordinate_system_on_name
before calling remove_transformation
.
tests/core/test_concatenate.py
Outdated
@@ -0,0 +1,36 @@ | |||
import pytest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the tests for concatenate
are in test_spatialdata_operations.py
, I will move this code there.
@timtreis I gave comments on the code and committed the suggestions that I made during review. Please have a look at the changes and if you are happy with them we can merge. |
…uffix-to-coordinate-systems
No description provided.